package com.zsr.rabbitmq.seven;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.zsr.rabbitmq.utils.RabbitMqUtils;

/**
 * 消费者1 用于测试Topic 交换机接收消息
 * @author zsr
 * @date 2021/8/8 23:29
 */
public class ReceiveLogsTopic02 {
    public static final String EXCHANGE_NAME="topic_logs";
    public static final String QUEUE_NAME="Q2";

    public static void main(String[] args) throws Exception{
        Channel channel = RabbitMqUtils.getChannel();
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        //队列绑定交换机
        channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "*.*.rabbit");
        channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "lazy.#");

        DeliverCallback deliverCallback=(consumerTag,delivery)->{
            System.out.println("RoutingKey为"+delivery.getEnvelope().getRoutingKey()+"的队列"+QUEUE_NAME+"，消息："+new String(delivery.getBody(),"UTF-8"));
        };
        
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,consumerTag->{});
    }
}
